home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 2.6 KB | 68 lines | [TEXT/GEOL] |
- Item forwarded by GOLDSMITH1 to LAWRENCE3
-
- Item 1277080 22-Aug-88 08:44
-
- From: A14 Carnegie Mellon, Rob Chandok
-
- To: MACAPP.TECH$ MACAPP Tech
- MACDTS Macintosh Developer Technical Supt.
-
- cc: ROSENSTEIN1 Rosenstein, Larry
-
- Sub: Bug in MPW Pascal
-
- Well, we just found possibly the worst compiler bug we can imagine (at this
- point). Hopefully, we are just being stupid and it isn't as bad as that.
-
- Here are the symptoms:
-
- Take a field of an object that is a string[255]. Do two writeln's of it. The
- first writeln comes out as garbage, and the second one is OK. Code looks like
- this:
-
- Writeln(myobject.fName); Writeln(myobject.fName);
-
- Here is our diagnosis:
-
- As everyone knows, the Pascal calling sequence was optimized for quick trap
- calls. Given that, the calling convention for pass-by-value structures over 4
- bytes is to pass a pointer on the stack and have the *callee* (not the caller)
- copy the value to some temporary storage.
-
- While this is all fine, and does speed things up for traps that do not modify
- their parameters, it does cause some problems when the value parameter is part
- of a relocatable object.
-
- Our applications are very segmented, and very large. So what happened in our
- case is that the pointer to a large value parameter field of an object was
- pushed onto the stack (for the 1st writeln, in the above example), and the
- procedure was called. However, in our case, the procedure's segment was *not
- loaded*, so the heap compacted, the segment loaded, and the writeln continued
- with AN INVALID POINTER FOR THE VALUE PARAMETER. The second writeln worked
- because the code segment was still loaded.
-
- So, as far as we can tell, we have to go through all our code and look for
- places that have fields of objects (larger than 4 bytes) being passed by value,
- and write code to copy them into temporary variables before the call. Sounds
- suspiciously like what people write compilers for, and exactly what value
- parameters are supposed to do in Pascal.
-
- In case you were wondering, the bug did not occur using writelns, and certainly
- is not specific to writelns. It also does not affect trap calls.
-
- The MPW pascal compiler DOES NOT DETECT THIS AND FLAG IT!!!!!!! We believe the
- MPW Pascal compiler should detect and warn about this situation, as it is at
- least (if not more) dangerous that the "passing fields as VAR parms" problem.
-
- It would be nice to hear that this is fixed in Pascal 3.0.
-
-
- Rob Chandhok
- John Pane
- Glen Meter
-
- CMU/Computer Science Dept.
-
-
-
-